/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.metier.ProjetMetier;
import com.metier.ProspectsMetier;

/**
 * 
 * @author moussa
 */
public class PanelAjouterProspect extends javax.swing.JPanel {
	private String typeChoisi;

	/**
	 * Creates new form PanelAjouterProspect
	 * 
	 */
	public PanelAjouterProspect() {
	//	initComponents();
	}
public PanelAjouterProspect(JButton boutonAnnuler){
	
	initComponents(boutonAnnuler);
	
}
	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents(JButton  bouttonAnnuler) {

		jLabel1 = new javax.swing.JLabel();
		typeProspect = new javax.swing.JComboBox();
		jLabel2 = new javax.swing.JLabel();
		textNumero = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		textCommentaire = new javax.swing.JTextArea();
		jLabel4 = new javax.swing.JLabel();
		dateCreation = new com.toedter.calendar.JDateChooser();
		buttonValider = new javax.swing.JButton();
		buttonAnnuler = new javax.swing.JButton();

		setBackground(new java.awt.Color(128, 130, 133));
		setMaximumSize(new java.awt.Dimension(1050, 375));
		setMinimumSize(new java.awt.Dimension(1050, 375));
		setPreferredSize(new java.awt.Dimension(1050, 375));

		jLabel1.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabel1.setForeground(new java.awt.Color(255, 255, 255));
		jLabel1.setText("Type :");

		typeProspect.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		typeProspect.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Demarche Physique", "Demarche Telephonique",
						"Maill" }));
		typeProspect.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				typeChoisi = (String) typeProspect.getSelectedItem();
			}
		});
		jLabel2.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabel2.setForeground(new java.awt.Color(255, 255, 255));
		jLabel2.setText("Numero :");

		jLabel3.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabel3.setForeground(new java.awt.Color(255, 255, 255));
		jLabel3.setText("Commentaire :");

		textCommentaire.setColumns(20);
		textCommentaire.setRows(5);
		jScrollPane1.setViewportView(textCommentaire);

		jLabel4.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabel4.setForeground(new java.awt.Color(255, 255, 255));
		jLabel4.setText("Date Create :");

		buttonValider.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		buttonValider.setText("VALIDER");
		buttonValider.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub

				boolean areEmpty;
				int indexe = -1;
				areEmpty = false;
				if (typeProspect.getSelectedItem().equals("Demarche Physique")) {
					indexe = 0;

				} else if (typeProspect.getSelectedItem().equals(
						"Demarche Telephonique")) {
					indexe = 1;
				} else if (typeProspect.getSelectedItem().equals("Maill")) {
					indexe = 2;

				} else {
					indexe = -1;
				}
				areEmpty = (!textNumero.getText().isEmpty()
						&& !textCommentaire.getText().isEmpty() && !(indexe == -1));
				if (!areEmpty) {

					JOptionPane.showMessageDialog(buttonValider,
							"veuillez remplir  les champs obligatoires");
				} else {
					if (JOptionPane.showConfirmDialog(getFrame(),
							"Voulez-vous vraiment ajouter le prospect ?",
							"Information", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
						ProspectsMetier prospect = new ProspectsMetier();
						prospect.addProspects(textCommentaire.getText(),
								typeChoisi, textNumero.getText(),
								dateCreation.getDate());
						        textCommentaire.setText("");
						        textNumero.setText("");
						        dateCreation.setDate(null);
						        JOptionPane.showMessageDialog(null, "Le prospect a été bien enregistré ");
						        
						        

					}

				}

			}
		});

		buttonAnnuler.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		buttonAnnuler.setText("Annuler");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(47, 47,
																		47)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jLabel2)
																				.addComponent(
																						jLabel1))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING,
																				false)
																				.addComponent(
																						typeProspect,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						195,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						textNumero))
																.addGap(357,
																		357,
																		357)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						 bouttonAnnuler)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														jLabel3)
																												.addComponent(
																														jLabel4))
																								.addGap(18,
																										18,
																										18)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														dateCreation,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														187,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jScrollPane1,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														187,
																														javax.swing.GroupLayout.PREFERRED_SIZE)))))
												.addGroup(
														layout.createSequentialGroup()
																.addGap(325,
																		325,
																		325)
																.addComponent(
																		buttonValider)))
								.addContainerGap(45, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(48, 48, 48)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														jScrollPane1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addGroup(
														layout.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
																.addComponent(
																		jLabel2)
																.addComponent(
																		textNumero,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addComponent(
																		jLabel3)))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel1)
												.addComponent(
														typeProspect,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(5, 5, 5)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		dateCreation,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		81,
																		Short.MAX_VALUE)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																				.addComponent(
																						buttonValider)
																				.addComponent(
																						 bouttonAnnuler))
																.addGap(56, 56,
																		56))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel4)
																.addContainerGap(
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)))));
	}// </editor-fold>//GEN-END:initComponents

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton buttonAnnuler;
	private javax.swing.JButton buttonValider;
	private javax.swing.JComboBox typeProspect;
	private com.toedter.calendar.JDateChooser dateCreation;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;

	public javax.swing.JButton getButtonAnnuler() {
		return buttonAnnuler;
	}

	public void setButtonAnnuler(javax.swing.JButton buttonAnnuler) {
		this.buttonAnnuler = buttonAnnuler;
	}

	public javax.swing.JComboBox getTypeProspect() {
		return typeProspect;
	}

	public void setTypeProspect(javax.swing.JComboBox typeProspect) {
		this.typeProspect = typeProspect;
	}

	public com.toedter.calendar.JDateChooser getDateCreation() {
		return dateCreation;
	}

	public void setDateCreation(com.toedter.calendar.JDateChooser dateCreation) {
		this.dateCreation = dateCreation;
	}

	public javax.swing.JTextArea getTextCommentaire() {
		return textCommentaire;
	}

	public void setTextCommentaire(javax.swing.JTextArea textCommentaire) {
		this.textCommentaire = textCommentaire;
	}

	public javax.swing.JTextField getTextNumero() {
		return textNumero;
	}

	public void setTextNumero(javax.swing.JTextField textNumero) {
		this.textNumero = textNumero;
	}

	public JPanel getFrame() {
		return this;

	}

	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextArea textCommentaire;
	private javax.swing.JTextField textNumero;
	// End of variables declaration//GEN-END:variables
}
